home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-15 | 1.6 KB | 66 lines | [TEXT/MMCC] |
-
- // * Comment Tzu
- // * ©1994 Chris K. Thomas. All Rights Reserved.
- // *
- // * 100 11 Oct 94 ckt
- // * 101 14 Oct 94 ckt - rewrote to decomment more intelligently
- // * & wrote DeleteText
-
- //future mods - check to see if there are comments after
- //a series of tabs after the return
-
- #include "TzuTools.h"
-
- pascal void main(Handle text);
-
- void DeleteText(Handle hText,long offsetToText,long textLen);
-
- // * Main entry point
- // text - handle to text to be modified
- pascal void main(Handle text)
- {
- EnterCodeResource();
-
- const char *commentText = "//";
- long sizeOfText = GetHandleSize(text);
- Ptr localText = *text;
-
- // delete “//” before text, since there isn't a return there usually
- if(localText[0] == '/' && localText[1] == '/')
- DeleteText(text,0,2);
-
- // replace returns + “//” with return
- for(long i=0; i<(sizeOfText-1); i++)
- {
- localText = *text;
- if(localText[i] == '\r' && localText[i+1] == '/' && localText[i+2] == '/')
- {
- DeleteText(text,i+1,2);
- i+=1;
- }
- }
-
- ExitCodeResource();
- }
-
- //Delete will probably be a callback in the
- //robustified TzuTool interface
- void DeleteText(Handle hText,long offsetToText,long textLen)
- {
- long hTextLen = GetHandleSize(hText);
- char hTextState = HGetState(hText);
- Ptr localText = NULL;
-
- // SetHandleSize might need to move the memory to resize it
- // which it can't do if the handle is locked
- HUnlock(hText);
- if(MemError()!=noErr) return;
-
- HLockHi(hText);
- localText = *hText;
-
- BlockMoveData(&localText[offsetToText+textLen],&localText[offsetToText],hTextLen - (offsetToText+textLen));
- SetHandleSize(hText,hTextLen - textLen);
-
- HSetState(hText,hTextState);
- }